package org.dftproject.genesis.ui.tasks;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dftproject.genesis.core.tasks.ITask;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

public class NavigationTaskHandler implements ITaskHandler {

	private static final Log log = LogFactory.getLog(NavigationTaskHandler.class);
	
	public static final String NAVIGATION_TASK_TYPE = "org.dftproject.genesis.ui.tasks.navigation";

	public void handleDoubleClick(ITask task) {
		String navigation = task.getAttribute("navigation");
		if ("openView".equals(navigation)) {
			IWorkbench workbench = PlatformUI.getWorkbench();
			IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
			IWorkbenchPage page = window.getActivePage();
			try {
				page.showView(task.getAttribute("viewId"));
			} catch (PartInitException e) {
				log.error("Failed to open view", e);
			}
		}
	}
	
}
